package com.ithema.mapper;

import com.ithema.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Select("select * from user where username=#{user} ")
    User findByUserName(String user);

    @Insert("insert into user(username,password,nickname,email,user_pic,create_time,update_time) values(#{user.username},#{user.password},#{user.nickname},#{user.email},#{user.userPic},now(),now())")
    int register(@Param("user") User user);

    //修改用户信息
    @Insert("update user set username=#{user.username},nickname=#{user.nickname},email=#{user.email},update_time=now() where id=#{user.id}")
    int update(@Param("user") User user);

    @Update("update user set user_pic=#{avatar} where id=#{id}")
    void updateAvatar(@Param("avatar") String avatarUrl, @Param("id") Integer id);
    //修改密码
    @Update("update user set password=#{password},update_time=now() where username=#{username}")
    int updatePassword(@Param("password") String password, @Param("username") String username);
}